from django.contrib.auth.hashers import check_password
from userapp.models import UserModel


class PhoneBackend:
    def authenticate(self, request, username=None, password=None):
        try:
            user_obj = UserModel.objects.get(phone=username)
        except UserModel.DoesNotExist:
            return None
        else:
            if user_obj and check_password(password, user_obj.password):
                return user_obj
            else:
                return None
